package com.example.cardgame.model

class Card(private var suit: String, private var rank: String, var isChosen:Boolean = false, var isMatched:Boolean = false) {
    companion object {
        val rankStrings = arrayOf("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K")
        val validSuits = arrayOf("♥", "♦", "♠", "♣")
    }

    override fun toString(): String {
        return suit + rank
    }


    fun match(otherCards: Array<Card>, matchType: Int): Int {
        var score = 0
        if (matchType == 3 && otherCards.size == 2) {
            // 三张牌的匹配逻辑
            val otherCard1 = otherCards[0]
            val otherCard2 = otherCards[1]
            val allSameRank = (rank == otherCard1.rank && rank == otherCard2.rank)
            val allSameSuit = (suit == otherCard1.suit && suit == otherCard2.suit)

            score = when {
                allSameRank && allSameSuit -> 46 // 三张点数和花色都一样
                allSameRank -> 23 // 三张点数一样
                allSameSuit -> 15 // 三张花色一样
                else -> 0
            }
        } else if (matchType == 2 && otherCards.size == 1) {
            // 两张牌的匹配逻辑
            val otherCard = otherCards[0]
            score = when {
                rank == otherCard.rank && suit == otherCard.suit -> 20 // 两张点数和花色都一样
                rank == otherCard.rank -> 10 // 两张点数一样
                suit == otherCard.suit -> 5 // 两张花色一样
                else -> 0
            }
        }
        return score
    }
}